﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;

namespace Runda.CMS.Portal.SyncManage
{
    public partial class InstrumentComponentList : BasePage
    {
        public Guid InstrumentID
        {
            get
            {
                if (hiddenInstrumentID.Value == string.Empty) return Guid.Empty;
                else return new Guid(hiddenInstrumentID.Value);
            }
            set
            {
                hiddenInstrumentID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["InstrumentID"] != null)
                {
                    Data_Bind();
                    InstrumentID = new Guid(Request.QueryString["InstrumentID"]);
                }
            }
        }
        private void Data_Bind()
        {
            SysDictionaryBll sysDicBll = new SysDictionaryBll();

            List<WsmComponentEntity> lists = sysDicBll.GetAll<WsmComponentEntity>(" and ComponentID in (select ComponentID from Cms_Wsm_ComponentInstrument where InstrumentID = '" + Request.QueryString["InstrumentID"] + "') order by ComponentDesc");
            this.RepeaterParms.DataSource = lists;
            this.RepeaterParms.DataBind();

        }

        protected void delete(object sender, EventArgs e)
        {
            if (dicids.Value.Trim() != "")
            {
                string[] dicidsArray = dicids.Value.Trim().Split(new char[] { ';' });
                for (int index = 0; index < dicidsArray.Length; index++)
                {
                    SysDictionaryBll bll = new SysDictionaryBll();
                    List<WsmComponentInstrumentEntity> dicEntitys = bll.GetAll<WsmComponentInstrumentEntity>(" and ComponentID = '" + new Guid(dicidsArray[index]).ToString() + "' and InstrumentID='" + InstrumentID.ToString() + "'");
                    if (dicEntitys != null && dicEntitys.Count > 0)
                    {
                        bll.Delete(dicEntitys[0]);
                    }
                }
                Data_Bind();
            }
        }

        protected void RepeaterParms_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                Data_Bind();
            }
        }
    }
}
